﻿using System;
using System.Web.Mvc;
using NoMiddleman.Core.Domain;
using NoMiddleman.Facades.DataTransferObjects;
using NoMiddleman.Facades.Facades;

namespace NoMiddleman.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private ClientFacade clientFacade;
        private readonly AdvertFacade advertFacade;

        public HomeController(ClientFacade clientFacade, AdvertFacade advertFacade)
        {
            this.clientFacade = clientFacade;
            this.advertFacade = advertFacade;
        }

        public ActionResult Index()
        {
            ViewData["Title"] = "Home Page";
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        private void ProdClient2()
        {
            AddressDTO address = new AddressDTO
                                  {
                                      City = "Tychy",
                                      FlatNumber = 3,
                                      Number = 6,
                                      Street = "Sienkiewicza",
                                  };

            ClientDTO client = new ClientDTO
                                {
                                    DateRegistered = DateTime.Now,
                                    Login = "przemek",
                                    Password = "przemek",
                                    IsIndividual = false,
                                    Regon = "743747474",
                                    Name = "agencja blabla",
                                    Address = address
                                };
            clientFacade.CreateClient(client);
        }

        private void ProdClient()
        {
            AddressDTO address = new AddressDTO
                                     {
                                         City = "Szczyglowiece",
                                         FlatNumber = 3,
                                         Number = 6,
                                         Street = "tow. Gierka"
                                     };


            ClientDTO client = new ClientDTO
                                   {
                                       Id = 9,
                                       Login = "hieronim",
                                       DateRegistered = DateTime.Now,
                                       Password = "wodzionka",
                                       Address = address,
                                       IsIndividual = true,
                                       FirstName = "hieronim",
                                       SurName = "ziemkiewicz"
                                   };
            clientFacade.CreateClient(client);

        }

        private void SampleAddAdvert()
        {
            AddressDTO address = new AddressDTO
            {
                City = "Mąkołowiec",
                FlatNumber = 1,
                Number = 14,
                Street = "Prusa"
            };

            AdvertDTO advert = new AdvertDTO();
            advert.IsForSale = true;
            advert.Price = 123000M;
            advert.DateAdded = DateTime.Now;
            advert.Title = "Fajne mieszkanie do sprzedania";
            advert.Description = "Sprzedaje bo nie lubie";
            advert.RealEstate = new RealEstateDTO();
            advert.RealEstate.IsFlat = true;
            advert.RealEstate.Address = address;
            advert.RealEstate.Description = "Mieszknaie dwupokojowe bla bla";
            advert.RealEstate.FloorNumber = 12;
            advert.RealEstate.HasElevator = true;
            advert.RealEstate.IsNew = false;
            advert.RealEstate.IsRaw = false;
            advert.RealEstate.RoomCount = 4;
            advert.RealEstate.Surface = 34;
            advert.Client = new ClientDTO { Id = 5 };

            advertFacade.AddAdvert(advert);

        }

        public ActionResult About()
        {
            ViewData["Title"] = "About Page";

            //ProdClient();
            //ProdClient2();
            SampleAddAdvert();


            return View();
        }
    }
}
